package com.probox.modules.controller.platfom;


import com.probox.common.core.enums.CmsType;
import com.probox.common.core.enums.DataStatus;
import com.probox.common.core.utils.SecurityUtils;
import com.probox.common.core.web.controller.BaseController;
import com.probox.common.core.web.domain.AjaxResult;
import com.probox.common.core.web.page.TableDataInfo;
import com.probox.common.log.annotation.Log;
import com.probox.common.log.enums.BusinessType;
import com.probox.common.security.annotation.PreAuthorize;
import com.probox.common.entity.domain.platfom.PlatformCms;
import com.probox.common.entity.domain.platfom.vo.PlatformCmsVo;
import com.probox.common.entity.service.platfom.IPlatformCmsService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (资讯/平台/公告)信息Controller
 *
 * @date 2021-06-11
 */
@RestController
@RequestMapping("/platform/cms")
public class PlatformCmsController extends BaseController {
    @Autowired
    private IPlatformCmsService platformCmsService;

    /**
     * 查询(资讯/平台/公告)信息列表
     */
    @PreAuthorize(hasPermi = "platform:cms:list")
    @GetMapping("/list")
    public TableDataInfo list(PlatformCms platformCms) {
        platformCms.setPlatformUid(SecurityUtils.getPlatformId());
        startPage();
        List<PlatformCmsVo> list = platformCmsService.queryList(platformCms);
        return getDataTable(list);
    }


    /**
     * 查询(资讯/平台/公告)信息列表
     */
    @GetMapping("/cmsApi/list")
    @ApiOperation(value = " 内容信息列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "OK", response = PlatformCms.class),
    })
    public AjaxResult listS(PlatformCms platformCms) {
        platformCms.setDataStatus(DataStatus.valid.getKey());
        platformCms.setPlatformUid(SecurityUtils.getPlatformId());
        startPage();
        List<PlatformCmsVo> list = platformCmsService.queryList(platformCms);
        return AjaxResult.successs(list, platformCmsService.queryListCount(platformCms));
    }

    /**
     * 获取(资讯/平台/公告)信息详细信息
     */
    @PreAuthorize(hasPermi = "platform:cms:query")
    @GetMapping(value = "/{cmsUid}")
    public AjaxResult getInfo(@PathVariable("cmsUid") Long cmsUid) {
        return AjaxResult.success(platformCmsService.selectPlatformCmsById(cmsUid));
    }

    @PreAuthorize(hasPermi = "platform:cms:query")
    @GetMapping(value = "/get/{cmsUid}")
    public AjaxResult getInfoOne(@PathVariable("cmsUid") Long cmsUid) {
        return AjaxResult.success(platformCmsService.get(cmsUid));
    }


    /**
     * 新增(资讯/平台/公告)信息
     */
    @PreAuthorize(hasPermi = "platform:cms:add")
    @Log(title = "内容信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlatformCms platformCms) {
        return toAjax(platformCmsService.insertPlatformCms(platformCms));
    }

    /**
     * 修改(资讯/平台/公告)信息
     */
    @PreAuthorize(hasPermi = "platform:cms:edit")
    @Log(title = "内容信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlatformCms platformCms) {
        return toAjax(platformCmsService.updatePlatformCms(platformCms));
    }

    /**
     * 删除(资讯/平台/公告)信息
     */
    @PreAuthorize(hasPermi = "platform:cms:remove")
    @Log(title = "内容信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/delN/{cmsUids}")
    public AjaxResult remove(@PathVariable Long[] cmsUids) {
        return toAjax(platformCmsService.deletePlatformCmsByIds(cmsUids, CmsType.notice.getKey()));
    }

    @PreAuthorize(hasPermi = "platform:cms:remove")
    @Log(title = "内容信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/delI/{cmsUids}")
    public AjaxResult removeI(@PathVariable Long[] cmsUids) {
        return toAjax(platformCmsService.deletePlatformCmsByIds(cmsUids, CmsType.information.getKey()));
    }

    @PreAuthorize(hasPermi = "platform:cms:remove")
    @Log(title = "内容信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/delP/{cmsUids}")
    public AjaxResult removeP(@PathVariable Long[] cmsUids) {
        return toAjax(platformCmsService.deletePlatformCmsByIds(cmsUids, CmsType.platformInfo.getKey()));
    }

}
